{extend name="base" /} {block name="body"}
<div class="layui-body">
	<div class="navbar">
		<a><cite>系统设置</cite></a>&nbsp;<span class="layui-box">&gt;</span>
		<a href=""><cite>数据库还原</cite></a>
	</div>
	<!--tab标签-->
	<div class="layui-tab layui-tab-brief">
		<div class="layui-tab-content">
			<table class="layui-table">
				<thead>
					<tr class="long-th">
						<th>备份名称</th>
						<th>卷数</th>
						<th>压缩</th>
						<th class="hidden-sm hidden-xs">数据大小</th>
						<th class="hidden-sm hidden-xs">备份时间</th>
						<th style="border-right:#CCC solid 1px;">操作</th>
					</tr>
				</thead>
				<tbody>
					{foreach name="data_list" item="v"}
					<tr>
						<td class="text-center" height="28">{$v.time|date='Ymd-His',###}</td>
						<td class="text-center">{$v.part}</td>
						<td class="text-center">{if condition="$v['compress'] eq 'GZ'"}{$v.compress}{else/}无压缩{/if}</td>
						<td class="hidden-sm hidden-xs">{$v.size|format_bytes}</td>
						<td class="text-center" class="hidden-sm hidden-xs">{$key}</td>
						<td class="text-center">
							<a class="db-import confirm-rst-url-btn layui-btn" data-info="你确定要还原吗？" href="{:url('restore?time='.$v['time'])}" title="还原">
								<i class="ace-icon fa fa-reply-all bigger-130"></i> 还原
							</a>
							{if condition="$v['compress'] eq 'GZ'"}
							<a class="db-import layui-btn layui-btn-status" href="{:substr(config('backup.db_path'),1)}{$v.time|date='Ymd-His',###}-{$v.part}.sql.{$v.compress}" title="下载">
								{else/}
								<a class="db-import" href="{:substr(config('backup.db_path'),1)}{$v.time|date='Ymd-His',###}-{$v.part}.sql" title="下载">
									{/if}
									<i class="ace-icon fa fa-cloud-download bigger-130"></i> 下载
								</a>
								<a class="confirm-rst-url-btn layui-btn layui-btn-error" href="{:url('del?time='.$v['time'])}" data-info="你确定要删除吗？" title="删除">
									<i class="ace-icon fa fa-trash-o bigger-130"></i> 删除
								</a>
						</td>
					</tr>
					{/foreach}
					<tr>
						<td height="50" colspan="7" align="left">&nbsp;</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>

{/block} {block name='script'}

<script>
	$(function() {
		$('body').on('click', '.confirm-rst-url-btn', function() {
			var $url = this.href,
				$info = $(this).data('info');
			if($info == "你确定要还原吗？") {
				window.onbeforeunload = function() {
					return "正在还原数据库，请不要关闭！"
				}
				layer.confirm($info, {
					icon: 3
				}, function(index) {
					layer.close(index);
					$.get($url, function(data) {
						window.onbeforeunload = function() {
							return null
						}
						if(data.code == 1) {
							layer.alert(data.msg, {
								icon: 6
							}, function(index) {
								layer.close(index);
								window.location.href = data.url;
							});
						} else {
							layer.alert(data.msg, {
								icon: 5
							}, function(index) {
								layer.close(index);
							});
						}
					}, "json");
				});
			} else {
				layer.confirm($info, {
					icon: 3
				}, function(index) {
					layer.close(index);
					$.get($url, function(data) {
						if(data.code == 1) {
							layer.alert(data.msg, {
								icon: 6
							}, function(index) {
								layer.close(index);
								window.location.href = data.url;
							});
						} else {
							layer.alert(data.msg, {
								icon: 5
							}, function(index) {
								layer.close(index);
							});
						}
					}, "json");
				});
			}
			return false;
		});
	});
</script>
<script>
	// 定义全局JS变量
	var GV = {
		current_controller: "{$controller}/import"
	};
</script>
{/block}